<?php 

class ErrorController extends Zend_Controller_Action {

    const NOTICE = 'notice';
    const WARNING = 'warning';   
    const CRITICAL = 'critical';

    public function errorAction() {

		$errorLevel = self::WARNING;
		$errorTitle = 'unknown_error';
		$errorMessage = 'fatal_error_occured_during_processing';
		$httpCode = 500;
		$error = $this->_getParam('error_handler',null);
		$exception = $error['exception'];
		
		if (isset($error)) {
	
			switch ($error->type) {
				case Zend_Config_Exception:
					$httpCode = 500; 
					$errorTitle = 'The application has not been setup';         			
					break;
					
				case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
				case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
				$httpCode = 404;
					$errorTitle = 'Page not found';
					$errorMessage = 'The page you requested cannot be found. The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.';  
					break;
			
				case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER: 
					switch (get_class($exception)) { 
							case 'Zend_View_Exception' : 
								$httpCode = 500; 
								$errorTitle = 'view_processing_error'; 
						
								break; 
							case 'Zend_Db_Exception' : 
							case 'Zend_Db_Table_Row_Exception':
								$httpCode = 503; 
								$errorTitle = 'database_processing_error'; 
								break; 
							default:
								$httpCode = 500;
							$errorTitle = 'unknown_error';
						break;
					}       
				default:
					$httpCode = 500; 
					$errorMessage = 'a_global_application_error_just_occurred';
					break;
		 
				}
			}
	
		$this->_response->setHttpResponseCode($httpCode);
	
		$this->view->level = $errorLevel;
		$this->view->title = $errorTitle;
		$this->view->message = $errorMessage; 
		$this->view->exception = $exception;

		

    }

}
